Adding some more judges, here and there.
[and.git] / lib / Mi manual de algoritmos / version_maraton_suramericana_2008 / src / geometria / distance_point_to_line.cpp
blob89557236d1e0291ccbf4d3eb7e605c0f0b9158ee
1 /*
2 Returns the closest distance between point pnt and the line that passes through points a and b
3 Idea by: http://local.wasp.uwa.edu.au/~pbourke/geometry/pointline/
4 */
5 double distance_point_to_line(const point &a, const point &b, const point &pnt){
6 double u = ((pnt.x - a.x)*(b.x - a.x) + (pnt.y - a.y)*(b.y - a.y)) / distsqr(a, b);
7 point intersection;
8 intersection.x = a.x + u*(b.x - a.x);
9 intersection.y = a.y + u*(b.y - a.y);
10 return dist(pnt, intersection);